package com.bigstar.lolkor;

import android.app.AlertDialog;
import android.app.TabActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TabHost;
import android.widget.Toast;

public class Masteries extends TabActivity{
	
    @Override
    protected void onResume() {
        ChampionData.load(this);
        ItemData.load(this);
        Rune.load(this);
    	super.onResume();
    }

    
    
	@Override 
	public void onCreate(Bundle savedInstanceState) { 
		super.onCreate(savedInstanceState); 
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 
        ChampionData.load(this);
        ItemData.load(this);
        Rune.load(this);
		setContentView(R.layout.masteries); 
		 Resources res = getResources();
		 TabHost tabHost = getTabHost(); 
		 TabHost.TabSpec spec; 
		 Intent intent; 
 		if(getIntent().getExtras() != null){
			 intent = new Intent(this, Masteries_Offense.class);
			 intent.putExtra("builder", "on");
 			 spec = tabHost.newTabSpec("offense").setIndicator("공격(Offense)", 
 					 res.getDrawable(R.drawable.mastery_offense)) 
 					 .setContent(intent);
 			 tabHost.addTab(spec); 
 		 
 			 intent = new Intent(this, Masteries_Defense.class); 
			 intent.putExtra("builder", "on");
 			 spec = tabHost.newTabSpec("defense").setIndicator("방어(Defense)", 
 					 res.getDrawable(R.drawable.mastery_defense)) 
 					 .setContent(intent); 
 			 tabHost.addTab(spec); 
 		 
 			 intent = new Intent(this, Masteries_Utility.class); 
			 intent.putExtra("builder", "on");
 			 spec = tabHost.newTabSpec("utility").setIndicator("보조(Utility)", 
 					 res.getDrawable(R.drawable.mastery_utility)) 
 					 .setContent(intent);
 			 tabHost.addTab(spec);  
 			 tabHost.setCurrentTab(0);
 			 tabHost.setCurrentTab(1);
 			 tabHost.setCurrentTab(2);
 			 tabHost.setCurrentTab(0);
 			 Toast.makeText(this, "초기화는 메뉴버튼", Toast.LENGTH_LONG).show();
 		}else{
 			 intent = new Intent(this, Masteries_Offense.class);
 			 spec = tabHost.newTabSpec("offense").setIndicator("공격(Offense)", 
 					 res.getDrawable(R.drawable.mastery_offense)) 
 					 .setContent(intent);
 			 tabHost.addTab(spec); 
 		 
 			 intent = new Intent(this, Masteries_Defense.class); 
 			 spec = tabHost.newTabSpec("defense").setIndicator("방어(Defense)", 
 					 res.getDrawable(R.drawable.mastery_defense)) 
 					 .setContent(intent); 
 			 tabHost.addTab(spec); 
 		 
 			 intent = new Intent(this, Masteries_Utility.class); 
 			 spec = tabHost.newTabSpec("utility").setIndicator("보조(Utility)", 
 					 res.getDrawable(R.drawable.mastery_utility)) 
 					 .setContent(intent);
 			 tabHost.addTab(spec);  
 		}
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		boolean result = super.onCreateOptionsMenu(menu);
 		if(getIntent().getExtras() != null){
 			menu.add(Menu.NONE, 1, 0, "전체 마스터리 초기화");  
 			menu.add(Menu.NONE, 2, 1, "공격(Offense)마스터리 초기화");  
 			menu.add(Menu.NONE, 3, 2, "방어(Defense)마스터리 초기화");  
 			menu.add(Menu.NONE, 4, 3, "보조(Utility)마스터리 초기화"); 	
 		} 
		return result;   
	} 
	

	public boolean onOptionsItemSelected(MenuItem item) {
		switch(item.getItemId()){ 
		case 1:
			new AlertDialog.Builder(Masteries.this)
			.setTitle("알림")
			.setMessage("전체 마스터리를 초기화 하시겠습니까?")
			.setPositiveButton("예", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int whichButton) {
					for(int i = 0; i < Builder.masteries.length; i++){
						for(int j = 0; j < Builder.masteries[i].length; j++){
							Builder.masteries[i][j] = 0;
						}
					}
					Masteries_Defense.imageChange();
					Masteries_Offense.imageChange();
					Masteries_Utility.imageChange();
				}
			})
			.setNegativeButton("아니오", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int whichButton) {
				}
			})
			.create().show();
			break;
		case 2:
			new AlertDialog.Builder(Masteries.this)
			.setTitle("알림")
			.setMessage("공격(Offense)마스터리를 초기화 하시겠습니까?")
			.setPositiveButton("예", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int whichButton) {
					for(int j = 0; j < Builder.masteries[0].length; j++){
						Builder.masteries[0][j] = 0;
					}
					Masteries_Offense.imageChange();
				}
			})
			.setNegativeButton("아니오", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int whichButton) {
				}
			})
			.create().show();
			break;
		case 3:
			new AlertDialog.Builder(Masteries.this)
			.setTitle("알림")
			.setMessage("방어(Defense)마스터리를 초기화 하시겠습니까?")
			.setPositiveButton("예", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int whichButton) {
					for(int j = 0; j < Builder.masteries[1].length; j++){
						Builder.masteries[1][j] = 0;
					}
					Masteries_Defense.imageChange();
				}
			})
			.setNegativeButton("아니오", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int whichButton) {
				}
			})
			.create().show();
			break;
		case 4:
			new AlertDialog.Builder(Masteries.this)
			.setTitle("알림")
			.setMessage("보조(Utility)마스터리를 초기화 하시겠습니까?")
			.setPositiveButton("예", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int whichButton) {
					for(int j = 0; j < Builder.masteries[2].length; j++){
						Builder.masteries[2][j] = 0;
					}
					Masteries_Utility.imageChange();
				}
			})
			.setNegativeButton("아니오", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int whichButton) {
				}
			})
			.create().show();
			break;
		}
		return ( super.onOptionsItemSelected(item)); 
	}
}
